import jsonp from "common/js/jsonp"
import {commonParams, options} from "./config"
import axios from 'axios'

// getRecommend方法的api有问题，暂且用mock数据代替
export function getRecommend() {
    const url = 'https://c.y.qq.com/musichall/fcgi-bin/fcg_yqqhomepagerecommend.fcg'

    const data = Object.assign({}, commonParams, {
        platform: 'h5',
        uin: 0,
        needNewCode: 1
    })

    return jsonp(url , data, options)
}

export function getDiscList() {
    const url = '/api/getDiscList'

    const data = Object.assign({}, commonParams, {
        platform: 'yqq.json',
        hostUin: 0,
        sin: 0,
        ein: 29,
        sortId: 5,
        needNewCode: 0,
        categoryId: 10000000,
        rnd: Math.random(),
        format: 'json'
    })

    return axios.get(url, {
        params: data
    }).then((res) => {
        return Promise.resolve(res, data)
    })
}

// 获取推荐歌单详情列表
export function getSongList (disstid) {
    const url = '/api/getSongList'

    const data = Object.assign({}, commonParams, {
        disstid,
        type: 1,
        json: 1,
        g_tk: 808397969,
        utf8: 1,
        onlysong: 0,
        new_format: 1,
        platform: 'yqq.json',
        hostUin: 0,
        needNewCode: 0,
        format: 'json',
        inCharset: 'utf8'
    })

    return axios.get(url, {
        params: data
    }).then((res) => {
        return Promise.resolve(res)
    })
}